package org.rambadger.command.axon;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Annotation used to configure indexes on a mapped collection
 *
 * @see MongoBundle#makeIndexes(com.mongodb.DBCollection, Class)
 */
@Target(TYPE)
@Retention(RUNTIME)
public @interface MongoIndexes {
    /**
     * List of one or more indexes to configure on the collection
     *
     * @return the indexes
     */
    public Index[] value() default {};

    /**
     * Configures a single index on a field or group of fields.
     */
    public static @interface Index {
        /**
         * Identifying name for the index
         *
         * @return the index name
         */
        public String name() default "";

        /**
         * A list of one or more keys to include in the index
         *
         * @return the keys
         */
        public Key[] keys();

        /**
         * Whether to enforce uniqueness on the index
         *
         * @return whether to enforce uniqueness on the index
         */
        public boolean unique() default false;
        //Define additional properties as needed
    }

    /**
     * A single field included in a index
     */
    public static @interface Key {
        /**
         * The <a href="http://docs.mongodb.org/manual/core/index-single/#indexes-on-embedded-fields">path</a> to the field that needs to be indexed
         *
         * @return the path to the field being indexed
         *
         * @see <a href="http://docs.mongodb.org/manual/core/indexes/"></a>
         */
        public String name();

        /**
         * Whether to maintain the index in ascending order, as opposed to decending
         *
         * @return whether to maintain the index in ascending order
         */
        public boolean ascending() default true;
    }
}
